--- title: Creating a Geospatial blog with blogdown Part 2. A vector map. author: UQGSAC date: '2021-10-28' slug: a-vector-map categories: - spatial - visualisation series: - series-setup tags: - RStats - vector ---

Load necessary packages

library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
library(tmap)

Get the data

The process to get the data is stored in a script (scripts/get_osm_data.R), instead of integrating it into this R Markdown file. This allows us to not overload the data provider but always querying the API, every single time the article is rendered! (And we don’t need to process the data every time either.)

Here, we only need to read the data from a file that was previously created:

green_space <- st_read("data/green_spaces.geojson")
## Reading layer `green_spaces' from data source 
##   `C:\R_projects\blog_website\content\english\post\2021-10-28-a-vector-map\data\green_spaces.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 5825 features and 3 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 152.6764 ymin: -27.67486 xmax: 153.4664 ymax: -27.00613
## Geodetic CRS:  WGS 84

Visualise on a slippy map

The tmap package is useful to visualise vector data on a slippy map.

tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(green_space) +
  tm_polygons(col = c("#43C467"), alpha = 0.5)

Data is copyright OSM contributors but release under an ODBL licence.